package org.casscommunity.sights.shared.event;

import java.util.ArrayList;
import java.util.List;

import org.casscommunity.sights.shared.event.handler.ConstraintViolationEventHandler;
import org.casscommunity.sights.shared.validation.ConstraintViolationDto;

import com.google.gwt.event.shared.GwtEvent;

public class ConstraintViolationEvent extends GwtEvent<ConstraintViolationEventHandler> {

	private static Type<ConstraintViolationEventHandler> TYPE = new Type<ConstraintViolationEventHandler>();
	
	public static Type<ConstraintViolationEventHandler> getType() {
		if (TYPE == null) {
			TYPE = new Type<ConstraintViolationEventHandler>();
		}
		return TYPE;
	}
	
	private List<ConstraintViolationDto> violations;
	
	public ConstraintViolationEvent() {
		violations = new ArrayList<ConstraintViolationDto>();
	}
	
	public ConstraintViolationEvent(List<ConstraintViolationDto> violations) {
		this.violations = violations;
	}
	
	@Override
	public Type<ConstraintViolationEventHandler> getAssociatedType() {
		return TYPE;
	}

	@Override
	protected void dispatch(ConstraintViolationEventHandler handler) {
		handler.processViolations(violations);
	}
	
	// for testing
	public List<ConstraintViolationDto> getViolations() {
		return violations;
	}

}
